	package net.narusas.aceauction.push.db;

import java.util.Date;
import java.util.List;

import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Restrictions;

import net.narusas.aceauction.push.model.Message;

public class MessageDAOHibernate extends GenericDaoHibernate<Message, Long>
		implements MessageDAO {

	protected MessageDAOHibernate() {
		super(Message.class);
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<Message> findByOvertimed(Date timestamp) {
		return (List<Message>) getHibernateTemplate().findByCriteria(
			DetachedCriteria.forClass(clazz).add(//
				Restrictions.or(//
						Restrictions.lt("sendTime", timestamp),//
						Restrictions.isNull("sendTime")//
				)
			).add(Restrictions.eq("done", false))
		);
	}
}
